﻿var isTooling = ref.ExpenseType.getValue();
var controller = this.lookupController();
var status = controller.analysis().status;
var vm = this.lookupViewModel();
var isInquiryCall = vm.get('NebulogyForm.isInquiryCall');
var ukCrossCharge = ref.UKCrossCharge.getValue();

if (isTooling == '5' && (context.colIdx == 1 || context.colIdx == 2)) {
    for (var i = 1; i < store.data.items.length; i++) {
        var firstRecord = store.data.items[0];
        var record2 = store.data.items[i];
        if (record2) {
            record2.set('ProjectActivity', firstRecord.get('ProjectActivity'));
        }
    }
}

if (isInquiryCall == 1 && record.previousValues) {
    if (context.field == 'Quantity' || context.field == 'UnitPrice') {
        var newValue = record.get('TotalPrice');
        var oldValue = record.get('originalTotalPrice');
        if (newValue > oldValue) {
            Ext.Msg.alert('System Tips', 'Total Price CANNOT be higher than the previous value.');
            record.set(context.field, record.previousValues[context.field]);
        } else {
            record.set('PriceDiffer', oldValue - newValue);
        }
    }
}
if (context.field == 'Quantity' || context.field == 'UnitPrice' || context.field == 'TaxRate') {
    if (record.get('TaxRate')) {
        var totalPrice = record.get('TotalPrice') || 0;
        record.set('GrossAmount', totalPrice * (1 + parseFloat(record.get('TaxRate'))));
    }
} else if (context.field == 'VendorCode') {
    var _editor = grid.getColumns()[context.colIdx].getEditor();

    Ext.each(_editor.store.data.items, function (r) {
        if (r.get('code') == record.get('VendorCode')) {
            record.set('VendorName', r.get('_name'));
        }
    });
}
